<?php
require_once ('class.phpmailer.php');
class EcsSendMail {

    public static function SendMail($mailArr, $tplReplaceArr=array(), $body=NULL) {

        $mail = new PHPMailer();

        $mail->IsMail();
        $mail->Host = EMAIL_HOST;
        $mail->SetFrom(EMAIL_FROM, EMAIL_FROM);
        $mail->Subject = $mailArr['subject'];
        $body = '';
        $msgTpl = $mailArr['msgtpl'];
        
        
        
        if (file_exists($msgTpl)) {
            
            
            $body = file_get_contents($msgTpl,true);
             
        }
       
        foreach ($tplReplaceArr as $key => $value) {
            $body = str_replace($key, $value, $body);
        }
        
       
        $mail->ContentType = 'text/plain';
        $mail->IsHTML(true); // send as HTML
        $mail->Body = $body;


        if (array_key_exists('to', $mailArr)) {
            $toArr = explode(',', $mailArr['to']);
            if (!empty($toArr)) {
                foreach ($toArr as $to) {
                    $mail->AddAddress($to);
                }
            }
        }


        if (array_key_exists('cc', $mailArr)) {
            $ccArr = explode(',', $mailArr['cc']);
            if (!empty($ccArr)) {
                foreach ($ccArr as $cc) {
                    $mail->AddBCC($cc);
                }
            }
        }


        if (array_key_exists('bcc', $mailArr)) {
            $bccArr = explode(',', $mailArr['bcc']);
            if (!empty($bccArr)) {
                foreach ($bccArr as $bcc) {
                    $mail->AddBCC($bcc);
                }
            }
        }
        
        $mail->Send();
    }

}

?>